﻿using CRMExam.Database;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.AspNet.Identity;

namespace CRMExam.Controllers
{
    [Authorize]
    public class BrandingController : Controller
    {
        public ActionResult BackgroundPicture()
        {
            if (!HttpContext.Response.Cookies.AllKeys.Contains("branding"))
            {
                using (CRMExam1Entities db = new CRMExam1Entities())
                {
                    var currentUser = User.Identity.GetUserId();

                    Customer customer = (db.AspNetUsers.FirstOrDefault(u => u.Id == currentUser)).Customer;

                    var cookie = new HttpCookie("branding", customer.PictureBackgroundUrl);
                    cookie.Expires.AddDays(365);
                    HttpContext.Response.Cookies.Add(cookie);
                }
            }
            return null;
        }
    }
}